<?php
require "../../system/framework.php";
require_once(config::$basePath."/system/api/simplehtmldom/simple_html_dom.php");


// user check


$contentId = $_REQUEST['content_id'];
$htmlId = $_REQUEST['html_id'];



 $data=db::getDataLine("content", "id='$contentId'");   



// falls Save
//if (isset($_REQUEST['content_id']))
if (isset($_REQUEST['save_button']))
    {

    //$data=db::getDataLine("content", "id='{$_REQUEST['content_id']}'");
    //property::saveContent();
    
    //$text=stripslashes(request::post("text"));
    $contentOrginal=file::readTextFile($data['content_filename'], false);
    $dom=str_get_html($contentOrginal);
//    $domArray=$dom->find("[com=text_editor]");
    $domArray=$dom->find("[id=$htmlId]");

    foreach ($domArray as $item)
        {
        //$text=$item->innertext;
        $item->innertext=stripslashes($_REQUEST['text']);
        }

    $content=$dom->save();
          
    
     /* $filename=$data['content_filename'];
        $text=request::post("content");

        $contentOrginal=file::readTextFile($filename, false);
        //$contentOrginal = dom::setTag("body", $content, $contentOrginal);
        $contentOrginal=dom::replaceInnerHtml("body", $content, $contentOrginal);*/

        file::createTextFile($data['content_filename'], $content, false);
    
    
    //$content = dom::getHtmlTags("body");
    $content = re::getTagInnerHtml("body", $content);
    
    

    //$filename=$data['content_filename'];
    //$text=request::post("content");

    //$contentOrginal=file::readTextFile($filename, false);
    //$contentOrginal = dom::setTag("body", $content, $contentOrginal);
    //$contentOrginal=dom::replaceInnerHtml("body", $text, $contentOrginal);

    //file::createTextFile($filename, $contentOrginal, false);


    /*$content = new content();
                               //$content->title = $title;
                               //$content->url = $url;
                               $content->contentId = $data['id'];   
                               $content->text = $content;
                               /*$content->contentFilename = $filenameFrom;
                               $content->template = $template;
                               $content->header = $header;*/

    /* $content->compile = true;
     $content->createPage();   */

    $compileText=new compile_text();
    //$compileText->phpScriptPath=$this->phpScriptPath;
    $compileText->codeFilename=$data['code_filename'];
    //$compileText->systemPath=$this->systemPath;

    $compileText->pageUrl=$data['_url'];
    $text=$compileText->compileText($content);

    // Body Text speichern
    //$fileName=config::$distributionPath . "/code/content/page_text_" . $codeFilename . ".php";
    file::createTextFile(config::$basePath . $data['code_filename'], $text, false);

    http::redirect($data['_url']);
 // exit;
    }



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Text Editor</title>
<script src="<?php echo config::$baseUrl;?>/api/ckeditor/ckeditor.js"></script>


<script type="text/javascript">
    window.onload = function()
    {
        CKEDITOR.replace('text');
    };
</script>

</head>
<body>








 


<?php
//require "../../system/framework.php";




 $contentOrginal=file::readTextFile($data['content_filename'], false);       

//$dom=str_get_html($data['text']);
$dom=str_get_html($contentOrginal);

//$domArray=$dom->find("[com=text_editor]");
$domArray=$dom->find("[id=$htmlId]");

foreach ($domArray as $item)
    {
    $text=$item->innertext;
    }


//    print_r($data);

?>

<form action = "">
    <textarea name="text" id="text" cols = "30" rows = "30">
    <?php echo $text; ?>
    </textarea>

    <input name = "content_id" type = "hidden" value = "<?php echo $contentId;?>" />
     <input name = "html_id" type = "hidden" value = "<?php echo $htmlId;?>" />    

    <input type = "submit" name = "save_button" value = "Save" />
</form>



</body>
</html>
